
console.log(location.href)
var url = location.href
var wangzhi = getUrlParams(url)
console.log(wangzhi)
let { categoryid } = wangzhi
let { productid } = wangzhi
let { span11 } = wangzhi
let { span12 } = wangzhi

//给h1的三个span和button设置点击事件
var span1 = document.querySelector('h1>span:nth-of-type(1)')
span1.onclick = function () {
    location.href = "../index.html"
}
var span2 = document.querySelector('h1>span:nth-of-type(2)')
span2.onclick = function () {
    location.href=`./12跳转页.html?brandtitleid=0&brandname=${span11}&categoryid=${categoryid}&span11=${span11}`
}
var span3 = document.querySelector('h1>span:nth-of-type(3)')
span3.onclick = function () {
    location.reload()
}
var button = document.querySelector('h1>button')
button.onclick = function () {
    location.reload()
}
span2.innerText = `${span11}>`

span3.innerText = span12
//获取图片信息
var main = document.querySelector('main')
console.log(main)
var xhr = new XMLHttpRequest()
xhr.open('get', `http://chst.vip:1234/api/getproduct?categoryid=${categoryid}&productid=${productid}`)
xhr.send()
xhr.onreadystatechange = function () {
    if (xhr.status === 200 && xhr.readyState === 4) {
        console.log(xhr.responseText)
        var x = JSON.parse(xhr.responseText).result[0]
        console.log(x)
        var html = ""
        html += `
        <div>
        ${x.productImg}
            <h1>${x.productName}</h1>
            <b>当前最低</b>
            <i>￥6000</i>
            <span>优质评论</span>
            <s>8266条</s>
        </div>
       ${x.bjShop}
        <ul>
        <h3>网友评价</h3>
            <li></li>
        </ul>`
        main.innerHTML = html
        //获取评论信息
        var ul=document.querySelector('main>ul')
        console.log(ul)
        var xhr2 = new XMLHttpRequest()
        xhr2.open('get', `http://chst.vip:1234/api/getproductcom?categoryid=${categoryid}&productid=${productid}`)
        xhr2.send()
        xhr2.onreadystatechange = function () {
            if (xhr2.status === 200 && xhr2.readyState === 4) {

                var x2 = JSON.parse(xhr2.responseText).result
                console.log(x2)
                var html2='  <h3>网友评价</h3>'
               x2.forEach(item2 => {
                   html2+=`<li>
                   <span>${item2.comName}</span>
                   <b>${item2.comTime}</b>
                   <p>${item2.comContent}</p>
                   <i>${item2.comFrom}</i>
                   </li>`
               });
               ul.innerHTML=html2
            }
        }
    }
}
//书写返回index.html功能
var fanhui = document.querySelector('header>a')
fanhui.onclick = function () {
    location.href = "../index.html"
}